package club.beimeng.emailsever2.controller;

import club.beimeng.emailsever2.service.EmailService;
import club.beimeng.emailsever2.utils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.internet.MimeMessage;
import java.util.Map;


@RestController
@RequestMapping("/emailSever2/email")
public class EmailController { // 提供账户的相关操作
    @Autowired
    public EmailService emailService;

    @ApiOperation("自定义html")
    @PostMapping("sendByHtml")
    public R emailByText(String recipients, String title, String html){
        boolean b = emailService.receiveTask(recipients,title,html);
        return b? R.ok():R.error();
    }

    @ApiOperation("自定义html")
    @PostMapping("sendByTemplete")
    public R emailByText(String recipients, String title, String templateCode ,@RequestBody Map<String,String> args){

        for (String s : args.keySet()) {
            System.out.println("s = " + s);
            System.out.println("args.get(s) = " + args.get(s));
        }

        boolean b = emailService.receiveTask(recipients,title,templateCode,args);
        return  b? R.ok():R.error();
//        return null;
    }

    @ApiOperation("提供MimeMessage")
    @PostMapping("sendByMimeMessage")
    public R emailByMimeMessage(MimeMessage mimeMessage){
        boolean b = emailService.receiveTask(mimeMessage);
        return  b? R.ok():R.error();
    }
}
